home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / risc_src.lha / risc_sources / comp / back_end / template.doc < prev   
Encoding:
Text File  |  1989-06-30  |  6.8 KB  |  151 lines

  1.  
  2. The following is a complete description of closures and templates.
  3.  
  4. The term UNIT refers to a closure that contains the free variables of a
  5. compiled expression produced by ORBIT. 
  6.  
  7. An object whose header is a template is said to be a closure over that template.
  8.  
  9. There are two kinds of templates: those internal to a code-vector (bytev)
  10. and those internal to a closure (unit).
  11.  
  12. Templates contain the following information and accessors:
  13.  
  14. pointer and scratch slots (unsigned)
  15.    These give the number of pointer (rootable) and scratch (non-rootable)
  16.    slots in closures over this template.  They are accessable by the primops
  17.    TEMPLATE-POINTER-SLOTS and TEMPLATE-SCRATCH-SLOTS.            
  18.    If the closure is internal to a closure then these two fields are adjoind to
  19.    get the offset of the closure in its surrrounding closure.
  20.  
  21. number of arguments       (signed)
  22.    If this field is 0, the closure is not callable
  23.    If it is > 0, it may be called and the field is 1 + the number of args
  24.       expected by the procedure
  25.    If it is < 0, it is a return point and the field is minus (1 + the number of
  26.       args expected)
  27.    Accessable with TEMPLATE-NARGS
  28.                  
  29. nary?                            
  30.   Specifies whether the closure is nary (lexpr)
  31.  
  32. handler-offset             (signed)
  33.   Given a template, this field is added (sign extended) to the pointer to get
  34.   the address of the handler code for the closure.  If this field is 0
  35.   there is no handler.
  36.  
  37. code-vector-offset          (unsigned)
  38.   This subtracted (zero extended) from a template gives the code vector.
  39.    
  40. annotation offset
  41.   This gives the offset in the UNIT of the vcell corresponding to a defined
  42.   procedure. If this closure is not lexicaly inferior to a defined procedure
  43.   then this field is 0.
  44.  
  45. H-bit
  46.   This is on if the closure is in the heap
  47.   Access with TEMPLATE-HEAPED-BIT?
  48.  
  49. I-bit
  50.   This is on if the closure is internal to another closure (see closure section)
  51.   Access with TEMPLATE-INTERNAL-BIT?
  52.  
  53. S-bit
  54.   This is on if the closure is a continuation and is inferior to another
  55.   continuation                            
  56.  
  57. This is what a template (internal to a code vector) looks like:
  58.  
  59. (VAX)
  60.  
  61. ------------------------------------------------------------------
  62. |     handler offset             |   annotation offset     |S|H|I|
  63. ------------------------------------------------------------------
  64. |    pointer     |   scratch     |  code vector offset           |             
  65. ------------------------------------------------------------------
  66. |    <---------- code            |   nargs       |?| template    |             
  67.                                  ---------------------------------
  68.                                  ^                ^
  69.                                  |                |
  70.                                  |                -----------  nary bit
  71.                                  |
  72.                                  -----------------------------  template pointer
  73.  
  74. (M68)
  75.      
  76.  
  77. ------------------------------------------------------------------
  78. |    annotation offset     |S|H|I|      handler offset           |
  79. ------------------------------------------------------------------
  80. |    pointer     |   scratch     |  code vector offset           |             
  81. ------------------------------------------------------------------
  82. |T|?|            |   nargs       |   code ----------->                         
  83. ----------------------------------                                
  84.  ^ ^                             ^                
  85.  | |-------- nary bit            |                
  86.  |                               |                
  87.  |----------- template bit       |
  88.                                  -----------------------------  template pointer
  89.  
  90.                                                         
  91. If the first instruction in code is the jump absolute instruction 
  92. then the template is internal to the unit and looks like
  93.                                                   
  94. (VAX)
  95.  
  96. ------------------------------------------------------------------
  97. |    pointer     |   scratch     |  offset of template in unit|00|             
  98. ------------------------------------------------------------------
  99. |  jump absolute instruction     |   nargs       |?| template |01|             
  100. ------------------------------------------------------------------
  101. |              address of auxiliary template                  |10|
  102. ------------------------------------------------------------------
  103.      
  104. (M68)
  105.  
  106. ------------------------------------------------------------------
  107. |    pointer     |   scratch     |  offset of template in unit   |             
  108. ------------------------------------------------------------------
  109. |T|?|            |   nargs       |   jump absolute instruction   |             
  110. ------------------------------------------------------------------
  111. |              address of auxiliary template                     |
  112. ------------------------------------------------------------------
  113.  
  114.  
  115. The auxiliary template is a normal template.  When the closure is called
  116. control is transferred to the auxiliary template.  When operation dispatch
  117. is attempted on the closure, the auxiliary template is used to get the handler.
  118.  
  119.  
  120. Closures
  121.  
  122. Closures are either stand-alone or internal to another closure
  123. If it is internal to another closure then pointer and scratch information is
  124. not relevant but we need to know the address of the surrounding closure.
  125. The offset is the pointer and scratch slots adjoined
  126. There is a restriction that the templates of a closure internal closure
  127. must be internal to a code vector, not the unit.
  128.  
  129. (RISC) Little endian
  130.  
  131. ------------------------------------------------------------------
  132. |     handler offset             |   annotation offset     |S|H|I|
  133. ------------------------------------------------------------------
  134. |                         code vector offset                     |             
  135. ------------------------------------------------------------------
  136. |           pointer              |   nargs       |?| template    |             
  137. ------------------------------------------------------------------
  138.                                  ^                ^
  139.                                  |                |
  140.                                  |                -----------  nary bit
  141.                                  |
  142.                                  -----------------------------  template pointer
  143.  
  144. ------------------------------------------------------------------
  145. |                   offset of template in unit                |00|             
  146. ------------------------------------------------------------------
  147. |        pointer                 |       0       |?| template |01|             
  148. ------------------------------------------------------------------
  149. |              address of auxiliary template                  |10|
  150. ------------------------------------------------------------------
  151.